import React, { Component } from "react";
import { withRouter } from "react-router-dom";

class Header extends Component {

    back = () => {
        this.props.history.goBack();
    }

    forward = () => {
        this.props.history.goForward();
    }

    render() {
        console.log(this.props)
        return (
            <div className="page-header">
                <h2>React Router Demo</h2>
                &nbsp;<button className="margin12" onClick={this.back}>回退</button>
                &nbsp;<button onClick={this.forward}>前进</button>
            </div>
        )
    }
}

export default withRouter(Header);
// withRouter可以加工一般组件，让一般组件获得路由组件的属性所特有的API
// withRouter返回的是一个新组件